package com.shuo.dsa.niuke;

/**
 * Created by shuoGG on 2018/10/18 0018
 */
public class Fibonacci {
    public int FibonacciRecur(int n) {
        if (n <= 1) return n;
        return FibonacciRecur(n - 1) + FibonacciRecur(n - 2);
    }


    public int Fibonacci(int n) {
        if (n <= 1) return n;
        int prepre = 0;
        int pre = 1;
        int cur = 0;
        for (int i = 2; i <= n; i++) {
            cur = pre + prepre;
            prepre = pre;
            pre = cur;
        }
        return cur;
    }
}
